#include <iostream>
#include <fstream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <liblas/liblas.hpp>
 
int main() {
    const char* lasfile = "../input.las";
    const char* pcdfile = "../output.pcd";
    std::ifstream ifs;
    ifs.open(lasfile, std::ios::in | std::ios::binary);
 
    liblas::ReaderFactory f;
    liblas::Reader reader = f.CreateWithStream(ifs);
    liblas::Header const& header = reader.GetHeader();
 
    std::cout << "Compressed: " << (header.Compressed() == true? "True" : "False") << std::endl;
    std::cout << "Signature: " << header.GetFileSignature() << std::endl;
 
    pcl::PointCloud<pcl::PointXYZI>::Ptr pointCloudPtr(new pcl::PointCloud<pcl::PointXYZI>);
    int count = header.GetPointRecordsCount();
    pointCloudPtr->width = 1;
    pointCloudPtr->height = count;
    pointCloudPtr->is_dense = false;
    pointCloudPtr->resize(pointCloudPtr->width * pointCloudPtr->height);
 
    int i = 0;
    while (reader.ReadNextPoint()) {
        liblas::Point const& p = reader.GetPoint();
        pointCloudPtr->points[i].x = p.GetX();
        pointCloudPtr->points[i].y = p.GetY();
        pointCloudPtr->points[i].z = p.GetZ();
        pointCloudPtr->points[i].intensity = p.GetIntensity();
 
        ++i;
    }
    pcl::io::savePCDFileASCII(pcdfile, *pointCloudPtr);
 
    return 0;
}
